package ibmetp.mis.controller.user;

import ibmetp.mis.common.Constants;
import ibmetp.mis.common.Message;
import ibmetp.mis.service.UserService;
import ibmetp.mis.serviceImpl.UserServiceImpl;
import ibmetp.mis.vo.User;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

/**
 * 更新用户
 * @author LAN DABIN
 * @create 2011-10-1
 *
 */
public class UserUpdateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    
    public UserUpdateServlet() {
        super();
       
    }

	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("Calling UserUpdateServlet...");
		request.setCharacterEncoding(Constants.ENCODING_UTF8);
		
		//获取用户参数
		User user=new User();
		user.setUserId(Long.valueOf(request.getParameter("userId")));
		user.setUserNo(request.getParameter("userNo"));
		user.setUserName(request.getParameter("userName"));
		user.setEmail(request.getParameter("email"));
		user.setPwd(request.getParameter("pwd"));
		user.setDescript(request.getParameter("descript"));
		
		//更新用户
		UserService us=new UserServiceImpl();		
		String result=us.updateUser(user);
		System.out.println(user);
		
		//如果有返回消息，则将消息发回页面
		if(result!=null){			
			response.setCharacterEncoding(Constants.ENCODING_UTF8);
			response.getWriter().print(JSONObject.fromObject(new Message(result)));
		}
		
	}

}
